/* global plus */
// src/mixins/backButtonMixin.js
export default {
    mounted() {
        // 处理物理返回键
        document.addEventListener('plusready', this.handleBackButton);
    },
    methods: {
        handleBackButton() {
            if (typeof plus !== 'undefined' && plus.key) {
                plus.key.addEventListener('backbutton', () => {
                    if (this.$route.path !== '/box1') {
                        this.$router.back();
                    } else {
                        if (confirm('再按一次退出应用')) {
                            plus.runtime.quit();
                        }
                    }
                });
            }
        }
    },
    beforeDestroy() {
        // 移除监听
        document.removeEventListener('plusready', this.handleBackButton);
    }
}